{% extends "nomcom/nomcom_private_base.html" %}
{# Copyright The IETF Trust 2015-2020, All Rights Reserved #}
{% load origin static %}
{% block subtitle %}- Administration{% endblock %}
{% block nomcom_content %}
    {% origin %}
    <h2 class="mt-3">Nomination status</h2>
    <table class="table table-sm table-striped-columns table-hover tablesorter">
        <thead class="wrap-anywhere">
            <tr>
                <th scope="col" data-sort="position">Position</th>
                <th scope="col" data-sort="open">Open</th>
                <th scope="col" data-sort="accepting-nom-num">Accepting nominations</th>
                <th scope="col" data-sort="accepting-fb-num">Accepting feedback</th>
                <th scope="col" data-sort="nom-num">Nominations</th>
                <th scope="col" data-sort="uniq-num">Unique nominees</th>
                <th scope="col" data-sort="acc-num">Accepted</th>
                <th scope="col" data-sort="decl-num">Declined</th>
                <th scope="col" data-sort="pend-num">Pending</th>
                <th scope="col" data-sort="resp-num">Questionnaire responses</th>
                <th scope="col" data-sort="comm-num">Comments</th>
            </tr>
        </thead>
        {% if stats %}
            <tbody class="table-group-divider">
                {% for item in stats %}
                    <tr>
                        <th scope="row">{{ item.position__name }}</th>
                        <td>{{ item.position.is_open|yesno:"Yes,No,No" }}</td>
                        <td>{{ item.position.accepting_nominations|yesno:"Yes,No,No" }}</td>
                        <td>{{ item.position.accepting_feedback|yesno:"Yes,No,No" }}</td>
                        <td>{{ item.nominations }}</td>
                        <td>{{ item.nominees }}</td>
                        <td>{{ item.accepted }}</td>
                        <td>{{ item.declined }}</td>
                        <td>{{ item.pending }}</td>
                        <td>{{ item.questionnaire }}</td>
                        <td>{{ item.comments }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        {% endif %}
        <tfoot class="table-group-divider">
            <tr>
                <th scope="row">Totals</th>
                <td>{{ totals.open }}</td>
                <td>{{ totals.accepting_nominations }}</td>
                <td>
                    {{ totals.accepting_feedback }}
                </td>
                <td>
                    {{ totals.nominations }}
                </td>
                <td>
                    {{ totals.nominees }}
                </td>
                <td>
                    {{ totals.accepted }}
                </td>
                <td>
                    {{ totals.declined }}
                </td>
                <td>
                    {{ totals.pending }}
                </td>
                <td>
                    {{ totals.questionnaire }}
                </td>
                <td>
                    {{ totals.comments }}
                </td>
            </tr>
            <tr>
                <th scope="row">
                    Unique nominee totals
                </th>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                    {{ unique_totals.nominees }}
                </td>
                <td>
                    {{ unique_totals.accepted }}
                </td>
                <td>
                    {{ unique_totals.declined }}
                </td>
                <td>
                    {{ unique_totals.pending }}
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
        </tfoot>
    </table>
    <h2 class="mt-3">
        Nominees by position
    </h2>
    <form class="my-3" method="get">
        <div class="mb-3">
            <label class="form-label" for="state">
                State:
            </label>
            <select class="form-select" name="state" id="state">
                <option value="">
                    All
                </option>
                {% for state in states %}
                    <option value="{{ state.slug }}"
                            {% if state.slug == selected_state %}selected{% endif %}>
                        {{ state.name }}
                    </option>
                {% endfor %}
            </select>
        </div>
        <div class="mb-3">
            <label class="form-label" for="position">
                Position:
            </label>
            <select class="form-select" name="position" id="position">
                <option value="">
                    All
                </option>
                {% for position in positions %}
                    <option value="{{ position.id }}"
                            {% if position.id == selected_position %}selected="selected"{% endif %}>
                        {{ position.name }}
                    </option>
                {% endfor %}
            </select>
        </div>
        <button class="btn btn-primary" name="submit" type="submit">Filter</button>
    </form>
    {% if is_chair and nomcom.group.state_id == 'active' %}
        <form class="form-inline" id="batch-action-form" method="post">
            {% csrf_token %}
        {% endif %}
        {% if nominee_positions %}
        <table class="table table-sm table-striped table-hover tablesorter"
               id="nominee-position-table">
            <thead>
                <tr>
                    {% if is_chair and nomcom.group.state_id == 'active' %}
                        <th scope="colgroup" colspan="2">
                            <i class="bi bi-check"></i>
                        </th>
                    {% endif %}
                    <th scope="col" data-sort="nominee">
                        Nominee
                    </th>
                    <th scope="col" data-sort="position">
                        Position
                    </th>
                    <th scope="col" data-sort="state">
                        State
                    </th>
                    <th scope="col" data-sort="questionnaire">
                        Questionnaire response
                    </th>
                </tr>
            </thead>
            <tbody>
                <!-- [html-validate-disable-block input-missing-label -- labelled via aria-label] -->
                {% for np in nominee_positions %}
                    <tr>
                        {% if is_chair and nomcom.group.state_id == 'active' %}
                            <td>
                                <input class="batch-select form-check-input"
                                       type="checkbox"
                                       value="{{ np.id }}"
                                       id="id-{{ np.id }}"
                                       aria-label="np.nominee.name"
                                       name="selected">
                            </td>
                            <td class="edit">
                                <a class="btn btn-primary btn-sm"
                                   href="{% url 'ietf.nomcom.views.edit_nominee' year np.nominee.id %}">
                                    Edit
                                </a>
                            </td>
                        {% endif %}
                        <td>
                            <a href="{% url 'ietf.person.views.profile' email_or_name=np.nominee.name %}">
                                {{ np.nominee.email.name_and_email }}
                            </a>
                            <a class="btn btn-primary btn-sm float-end"
                               href="{% url 'ietf.nomcom.views.view_feedback_nominee' year=year nominee_id=np.nominee.id %}#comment">
                                View feedback
                            </a>
                        </td>
                        <td>
                            {{ np.position.name }}
                        </td>
                        <td>
                            {{ np.state }}
                        </td>
                        <td>
                            {{ np.questionnaires|yesno:"Yes,No,No" }}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
            <p>No nominees.</p>
        {% endif %}
        {% if is_chair %}
            {% if nomcom.group.state_id == 'active' %}
                <div class="mb-3">
                    <label class="form-label" for="action">
                        Action:
                    </label>
                    <select class="form-select" name="action" id="action">
                        <option value="" selected="selected">
                            ---------
                        </option>
                        <option value="set_as_accepted">
                            Set as accepted
                        </option>
                        <option value="set_as_pending">
                            Set as pending
                        </option>
                        <option value="set_as_declined">
                            Set as declined
                        </option>
                        <option value="email">
                            Generate email list
                        </option>
                    </select>
                </div>
                <button class="btn btn-warning"  type="submit" title="Run action">
                    Apply
                </button>
            </form>
            {% if mailto %}
                <br>
                <a class="btn btn-primary btn-sm"
		   href="mailto:{{ mailto }}">Mail to selected nominees
                </a>
            {% endif %}
        {% endif %}
    {% endif %}
{% endblock %}